package com.laf.framework.config;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自定义 mq 的消息转换，使用 Jackson2JsonMessageConverter 来序列化和反序列化消息，默认使用 SimpleMessageConverter
 * json
 */
@Configuration
@ConditionalOnClass(RabbitTemplate.class) // 只有存在这个类才会加载这个配置类
public class MqConfig {
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }
}
